package scrum.server.project;

import ilarkesto.core.base.Utl;
import scrum.client.common.LabelSupport;
import scrum.client.common.ReferenceSupport;
import scrum.server.admin.User;
import scrum.server.common.Numbered;

public class ProjectGroup extends GProjectGroup implements Numbered, ReferenceSupport, LabelSupport,
Comparable<ProjectGroup> {

	public String getReferenceAndLabel() {
		return getReference() + " " + getLabel();
	}

	@Override
	public String getReference() {
		return scrum.client.project.ProjectGroup.REFERENCE_PREFIX + getNumber();
	}

	@Override
	public void updateNumber() {
		if (getNumber() == 0) setNumber(getProject().generateScenarioNumber());
	}

	@Override
	public boolean isVisibleFor(User user) {
		return getProject().isVisibleFor(user);
	}

	public boolean isEditableBy(User user) {
		return getProject().isEditableBy(user);
	}

	@Override
	public void ensureIntegrity() {
		super.ensureIntegrity();
		updateNumber();
	}

	@Override
	public String toString() {
		return getReferenceAndLabel();
	}

	@Override
	public int compareTo(ProjectGroup other) {
		return Utl.compare(getLabel(), other.getLabel());
	}
}